Method for detecting an anomalous image among a first dataset of images using an adversarial autoencoder

ABSTRACT

A method for detecting an anomalous image among a dataset of images using an Adversarial Autoencoder includes training an Adversarial Autoencoder in a first training with a training dataset of images, with the Adversarial Autoencoder being optimized such that a distribution of latent representations of images of the training dataset of images approaches a predetermined prior distribution and that a reconstruction error of reconstructed images of the training dataset of images is minimized. Subsequently, anomalies are detected in the latent representation and the Adversarial Autoencoder is trained in a second training with the training dataset of images, but taking into account the detected anomalies. The anomalous image among the first dataset of images is detected by the trained Adversarial Autoencoder dependent on at least one of the reconstruction error of the image and a probability density under the predetermined prior distribution.

CROSS-REFERENCE TO RELATED APPLICATIONS

The present application claims priority under 35 U.S.C. § 119 to EP17198775.3, filed in Europe on Oct. 27, 2017, the content of which ishereby incorporated by reference herein in its entirety.

FIELD OF THE INVENTION

The present invention relates to a method, a computer program, as wellas a computing device, for example, programmed processing circuitryconfigured, for detecting one or more anomalous images among a firstdataset of images using an Adversarial Autoencoder.

BACKGROUND

Adversarial Autoencoders are disclosed in A. Makhzani et al.,“Adversarial Autoencoders,” arXiv preprint arXiv:1511.05644 (2015). Amethod for anomaly detection is described in E. Principi et al.,“Acoustic Novelty Detection with Adversarial Autoencoders,” IEEE 2017International Joint Conference on Neural Networks (IJCNN), pp. 3324-3330(May 2017).

An unsupervised One-Class Support Vector Machine (SVM) algorithm isdisclosed in “B. Schölkopf et al., “Support vector method for noveltydetection,” Advances in neural information processing systems, pp.582-588 (2000).

SUMMARY

The presented method for detecting one or more anomalous images among afirst dataset of images uses an Adversarial Autoencoder being trained ina first training with a training dataset of images, where theAdversarial Autoencoder is optimized such that a distribution of latentrepresentations of images of the training dataset of images approaches apredetermined prior distribution and that a reconstruction error ofreconstructed images of the training dataset of images is minimized.After the first training of the Adversarial Autoencoder, anomalies aredetected in the latent representation and the Adversarial Autoencoder istrained in a second training with the training dataset of images, buttaking into account the detected anomalies. The one or more anomalousimages among the first dataset of images are detected by the trainedAdversarial Autoencoder dependent on at least one of the reconstructionerror of the image and the probability density under the predeterminedprior distribution.

The presented method addresses the problem of visual anomaly detectionby learning from an at least partly unlabeled training dataset ofimages, which can contain an unknown number of anomalies, i.e., a“polluted” training set. The method can reliably identify anomalies inimages that were not contained in the training set. The method can alsobe applied in an active semi-supervised setup, where the algorithm takesan unlabeled dataset as its input, and queries the user to supply labelsfor a small fraction of data points. A further advantage is that themethod is not restricted to only outputting an anomaly score, but canidentify the training examples that are likely anomalies, so that thefunction of the system can be checked by domain experts.

The method introduces further criteria for anomaly detection, whichreduce the number of false positives and false negatives by combiningreconstruction and latent information. By altering the training setduring training, the method becomes specifically robust against polluteddatasets. Furthermore, the interactive semi-supervised approach can makeoptimal use of very sparse feedback from domain experts that can providea small number of labels.

It does not require a representative set of all possible anomaliescontained in the training data. It is sufficient that anomalies manifestthemselves in a significant deviation from the normal dass, but therecan be many diverse forms of anomalies.

The method has a more general applicability than other methods strictlyrequiring that all training data is from the normal dass. Such methodsquickly lose performance if this condition is violated. For example,methods using normal autoencoders in a setup with polluted data alsolearn to reconstruct anomalies very well, and thus the threshold onreconstruction error does not provide a robust criterion for detectinganomalies. Instead, the presented method is applicable in the settingwhere no labels are needed for the training data, and a small fractionof the training data can be anomalous.

If domain experts are available for labeling a small fraction of thetraining data, the presented method can process the training data andsearch specifically for those examples, which would provide the greatestperformance gain if a label was known.

By using an Adversarial Autoencoder, the method gains control over thedesired distribution in latent space and can use a density estimate inlatent space as an additional criterion for anomaly detection. Thisleads to a better criterion than using the reconstruction error of theautoencoder alone. The Adversarial Autoencoder also serves as agenerative model of the learned data distribution and can be used togenerate samples from the normal or identified abnormal classes toverify that the learned model is meaningful.

If prior information about the nature of anomalies is known, e.g., theexpected number of different typically observed anomalies, this can beused in the Adversarial Autoencoder to shape the desired distribution inlatent space.

The presented method automatically detects training examples that arelikely to be anomalous during training, making the performance robust tochanging anomaly rates.

In preferred embodiments, the detection of the anomalies in the latentrepresentation is done using a one-class support vector machine or alocal outlier factor algorithm. The presented method can be used withvarious methods handling the detected anomalies. Preferred embodimentfor this anomaly handling include at least one of (a) anomalies detectedin the latent representation being excluded from the training set forthe second training, (b) using a weighted loss function for tuning theAdversarial Autoencoder in at least one subsequent training, whereanomalies detected in the latent representation receive a reduced weightin the at least one subsequent training, (c) modifying a reconstructiontarget for each of a set of the anomalies detected in the latentrepresentation to a noise-corrupted version of itself for at least onesubsequent training, and (d) modifying a reconstruction target for eachof a set of the anomalies detected in the latent representation to animage close or closest in the latent space that is identified as noanomaly in at least one subsequent training. Using these functionsseparately or in combinations provides a robust and effective trainingof the Adversarial Autoencoder.

In preferred embodiments, the method outputs an anomaly score for imagesin the first dataset of images calculated based on at least one of areconstruction error and a probability density under the predeterminedprior distribution. This provides a differentiated and precise feedbackon the anomaly.

In preferred embodiments, the method is used in visual qualityinspection, medical image analysis, visual surveillance, or automateddriving.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 schematically shows an exemplary Adversarial Autoencoderframework with a two-dimensional Gaussian as prior distribution,according to an example embodiment of the present invention.

FIG. 2 is a flowchart that illustrates a method for detecting ananomalous image with unsupervised training using polluted training data,according to an example embodiment of the present invention.

FIG. 3 is a flowchart that illustrates a method for detecting ananomalous image with semi-supervised training using polluted trainingdata, according to an example embodiment of the present invention.

DETAILED DESCRIPTION

A variety of machine learning methods exist to identify anomalies oroutliers in a given set of images. Whereas it is assumed that imagesfrom the normal class share many similar features, outliers arecharacterized by a significant deviation from the normal class.Furthermore, it is assumed that the training data is either entirelycomposed of normal images, or only a small fraction of the images areanomalies. Typical applications of visual anomaly detection are forvisual quality inspection, medical image analysis, or for surveillancetasks.

The approaches for anomaly detection can be classified as supervised,semi-supervised, or unsupervised, as follows.

Supervised: each image in the training set contains a label indicatingwhether it belongs to the normal dass or is an anomaly. This alsosubsumes the case where all available training data is assumed to benormal.

Semi-supervised: most images are unlabeled, but for some images, it isknown whether they are anomalies or belong to the normal class.

Unsupervised: no labels are known; whether an image is an anomaly needsto be learned by comparing characteristics of the majority class andeventual outliers.

A further distinction can be made between methods that only identifyanomalies on one fixed dataset, and those that learn from a training setand generalize to previously unseen images.

One approach for visual anomaly detection is the use of autoencoders,which are neural networks with multiple hidden layers that include anencoding stage and a decoding stage. The encoder is trained to map aninput image to a lower-dimensional latent representation, from which thedecoder learns to reconstruct the original image. The goal is tominimize the reconstruction error of the autoencoder. By having alower-dimensional latent representation, a bottleneck is introducedwhich requires the encoder to focus on characteristic features of theimage, and prevents learning trivial solutions such as an identityfunction. The quality of the autoencoder is measured by thereconstruction error, typically the mean squared error over all pixels.Since the target output of the autoencoder is the input image,autoencoder training is unsupervised.

Autoencoders can be used for anomaly detection on image and other data.The idea is that an autoencoder trained only on normal data learns amodel of the normal dass, i.e., it can reconstruct normal images withvery small training error, but the reconstruction error on anomalousdata will be higher. An anomaly detector based on autoencoders wouldthen impose a threshold on the reconstruction error and consider allimages that exceed the threshold as an anomaly. This has been appliedsuccessfully to visual and auditory quality inspection problems.

One assumption in autoencoder approaches for anomaly detection is thatall training examples are from the normal dass, which makes thoseapproaches fall into the category of supervised learning as definedabove, even though the auto-encoder training itself is unsupervised. Ina more realistic and more challenging scenario, the training set cancontain anomalies, but it is unknown beforehand which images areanomalous and which are not. This case of “polluted training data” islikely to occur in a real-world scenario where it might be tooburdensome or even impossible to have all training points labeled byhumans, or where there might be annotation error. For the consideredsets of “polluted training data,” it can be assumed that the fraction ofanomalies in the training data is low (in the range <5%) and that thenormal dass has relatively little variability, but anomalies can havevery diverse forms. In this scenario, the performance of autoencodersfor anomaly detection degrades already with small percentages ofanomalies.

Now, it is proposed to use an extension of autoencoders, an AdversarialAutoencoder for anomaly detection. A schematic framework is shown inFIG. 1. The Adversarial Autoencoder includes an encoder 12, a decoder14, and a discriminator network 16. Images 11 of a training set ofimages are input to the encoder 12, which encodes the inputs into latentrepresentations 13. The decoder 14 decodes the latent representativesinto reconstructed images 15. The encoder 12 and the decoder 14 of theAdversarial Autoencoder are trained to minimize the reconstruction errorof the images in the training set.

The Adversarial Autoencoder induces a prior distribution on the latentlow dimensional space. This prior distribution can be predetermined andcan be input into the Adversarial Autoencoder. Various probabilitydensity function can be used as a prior distribution. In a preferredembodiment for anomaly detection, a multivariate Gaussian is used, e.g.,a Standard Gaussian, such that latent representations of normal imagescluster around the origin. Alternatively, a mixture of Gaussiansdistribution with one or more dedicated rejection classes (foranomalies) can be used, especially when the number of different anomalyclasses is known. In FIG. 1, a two-dimensional Gaussian 17 is input intodiscriminator network 16 of the Adversarial Autoencoder. The AdversarialAutoencoder enforces that the distribution of the latent representationsof the input images of the training set of images follows the prescribedprior by training the discriminator network 16, which learns todistinguish representations for images from the desired priordistribution.

This procedure does not require any labels about the content of eachimage (i.e., whether it is an anomaly or not). By training theautoencoder, a latent representation of each image is learned, and theadversarial part of the Adversarial Autoencoder ensures that thedistribution of latent representations follows the given priordistribution. The overall training target is to optimize the AdversarialAutoencoder such that the latent representation becomesindistinguishable from the prior, while at the same time minimizing thereconstruction error in the decoder part.

Once the Adversarial Autoencoder is trained, it can be used to computetwo different indicators whether a presented image is an anomaly. First,a high reconstruction error (exceeding some threshold) is a sign for ananomaly. Second, a small probability density under the given priordistribution for the latent space is also an indicator that the imagemight be an outlier. A combination of the two measures is more robust indetecting anomalies than any single one of them.

In a preferred embodiment, the prior distribution is chosen such thatmost of the probability mass lies around the center of the distribution(e.g., the origin with a standard multivariate Gaussian), so the densityfor anomalies can be expected to be low. Images that have nearbyrepresentations in latent space can be expected to lead to similarimages after decoding. That means that even if images from differentclasses are mapped to nearby latent representations, the reconstructionerror will be significantly higher for one of them.

FIG. 2 schematically shows an exemplary embodiment of a method fordetecting an anomalous image with unsupervised training based onpolluted training data, using an Adversarial Autoencoder. In thisembodiment, it is assumed that no labels for the images are availableduring the whole training procedure, but there is a rough estimate ofthe anomaly rate α. In this case, an anomaly detection in the latentspace can be performed, e.g., with the unsupervised One-Class SupportVector Machine algorithm. In this approach, the kernel-transformednormal data can be separated from the origin by a decision boundarywhereas the kernel-transformed anomalies lie on the other side of theboundary closer to the origin. It requires to specify the anomaly rate αwhich is then translated into a regularization parameter β=1/(α×numberof training examples) for the One-class Support Vector Machine, whichcontrols how many data points are expected to lie outside of thedecision boundary. The data points identified as potential anomalies arethen processed to modify the training dataset. Training of theAdversarial Autoencoder is then continued on the modified dataset.

In this embodiment, a second anomaly rate v, which is a fraction of theassumed anomaly rate α, is defined. This second anomaly rate v is thenused for iteratively detecting anomalies during training.

The unsupervised training procedure shown in FIG. 2 works as follows. Ina step 21, a training set of images is loaded and used in step 22 totrain the Adversarial Autoencoder for a certain number of iterations. Ingeneral, it should not be too large to avoid exhaustive training on alldata including anomalies. This yields an initial latent representationfor each image. In Step 23, potential anomalies in the current latentspace are detected. To this end, a One-class Support Vector Machine istrained with regularization parameter β computed from the update-stepanomaly rate v. In step 24, it is checked whether the detected anomaliesreach anomaly rate α or a user-defined rate close to α. If not, themethod continues with step 25, taken into account the detected orpotential anomalies.

The functions 251/252, 253/254, 255/256, and 257/258 can be used asalternatives for handling the anomalies, but also combinations of thedescribed approaches are possible. At least one of the shown functionsis implemented or activated. In step 251, it is checked whetherpotential anomalies should be excluded from the training set until thenext reset of the dataset occurs (step 21). If yes, this is carried outin step 252. In step 253, it is checked whether a weighted loss functionshould be used for tuning the auto-encoder and potential anomaliesreceive a reduced weight for the following training steps. If yes, thisis carried out in step 252. In step 255, it is checked whether thereconstruction target for a detected anomaly should be modified to anoise-corrupted version of itself, such that the autoencoder no longertries to perfectly reconstruct such images. If yes, this is carried outin step 256. In step 257, it is checked whether the reconstructiontarget for a detected anomaly should be changed to the next closestimage (in latent space) that is identified as belonging to the normaldass. This also has the effect of focusing the training of theautoencoder on those examples that are likely normal. If yes, this iscarried out in step 258.

After such handling of the detected anomalies, the AdversarialAutoencoder is again trained for a certain number of iterations. Thenumber of training iterations depends on the task. In general, it shouldnot be too large to avoid exhaustive training on all data includinganomalies. Steps 22-25 are repeated until the fraction of detectedanomalies reaches a percent or a user-defined rate close to α and thisis determined in step 24. In this case, the method proceeds to step 26where it is checked whether the training of the Adversarial Autoencoderhas sufficiently converged. If this is the case, the training isconcluded with step 27 and the Adversarial Autoencoder can be used fordetecting anomalies in sets of images. If the training has not yetsufficiently converged, the training of the Adversarial Autoencoder iscontinued with step 21, loading or resetting the training set ofpictures. However, the current weights are still used.

FIG. 3 schematically shows an exemplary embodiment of a method fordetecting an anomalous image with semi-supervised training usingpolluted training data. Instead of a fully unsupervised approach asdescribed above, the method for detecting anomalies in images can alsoincorporate sparse interactive feedback by the user, in which he ispresented with potential anomalies and decides whether they belong tothe normal class or not. This semi-supervised approach shown in FIG. 3is described in the following, focusing on the differences to theunsupervised approach shown in FIG. 2.

Steps 31 and 32 correspond to steps 21 and 22, respectively, describedabove. In step 33 a, as in step 23, a One-class Support Vector Machinewith regularization parameter β computed from the update-step anomalyrate v is trained, but all images previously labeled (especially by userfeedback) as normal or anomalies are excluded. Step 34 corresponds tostep 24 described above. In step 35 a, the automatically and theuser-detected anomalies are handled. The functions 351-358 usedcorrespond to functions 251-258 described above. After step 35 a, themethod again continues with step 32, whereas in the training alluser-identified normal instances are included for training. Steps 32-35are repeated until the fraction of detected anomalies reaches a percentand this is determined in step 34. In this case, the method proceeds tostep 36 where it is checked whether the training of the AdversarialAutoencoder has sufficiently converged. If this is the case, thetraining is concluded with step 37 and the Adversarial Autoencoder canbe used for detecting anomalies in sets of images. If the training hasnot yet sufficiently converged, the training of the AdversarialAutoencoder is continued with step 31, loading or resetting the trainingset of pictures. However, the current weights are still used.

The number of images the user has to label can be implemented as aparameter that the user can choose, e.g., in addition to choosing howfrequently he is asked about newly identified anomalies. Furthermore, itcan be implemented that the user can choose how detected potentialanomalies are handled, i.e., which of the functions in step 35 a shouldbe used.

The One-class Support Vector Machine provides a measure of how closeinstances are to the decision boundary. The most informative examplesfor anomaly detection are those that are close to the boundary, andshould be preferentially presented to the user to be labeled. Thepotential anomalies can be sorted by their distance to the decisionboundary, and the user can select that the potential anomalies presentedto him must lie within the top x-% of the examples closest to theboundary.

The anomaly decision threshold can be chosen based on reconstructionerror and can depend on the distribution of reconstruction errorsobtained during training. Several alternatives are possible to determinethis threshold, several examples of which include:

1. the maximum reconstruction error observed during training (this makessense if the training set contains only normal data);2. a percentile of reconstruction errors, e.g., the 95% percentile, suchthat only 5% of all training images exceed this reconstruction error;and3. an adaptive threshold that depends on the expected anomaly rate α,such as the (1−α)% percentile.

After the Adversarial Autoencoder is trained, it can be used to identifyanomalies in new data sets. A new image is processed by the encoder anddecoder of the Adversarial Autoencoder, and preferably a combination ofreconstruction error and density of the latent representation(especially in a 2D space) is used to classify the new image as normalor as an anomaly.

Already in the unsupervised case it is often possible to distinguishnormal for anomalous data by learning a boundary in the 2-dimensionalspace where one axis shows the reconstruction error, and the second axisshows the density of the latent representation. If labels from userfeedback are known, these can be used to improve the separation betweenthe two classes, e.g., by increasing their weight in computing the errorof the classifier compared to the unlabeled points.

The presented method has the potential to be used in a number ofpractically relevant domains.

In visual quality inspection, photos of parts produced by a machine arecollected, and an automated identification of potentially faulty partsis performed. Under the assumption that the majority of all producedparts is functional, this becomes a typical anomaly detection task, andhistorical yield rates (from customer feedback or domain experts) canprovide a good estimate of the expected anomaly rate. Since it isexpensive and time consuming to generate labels, the unsupervisedapproach is particularly interesting for industrial mass production, butalso for fabrication of precision machinery (e.g., 3D printing).

In visual surveillance, frames from a video stream can be recorded andcompared. Unusual recordings correspond to anomalies, which mightrequire the attention of a human supervisor or activate some alarm. Thishas obvious applications for surveillance cameras, but could inprinciple also be used to detect faulty sensors.

In medical image analysis, anomaly detection helps in identifyingunusual structures in medical images, which might provide evidence for amedical condition (under the assumption that the vast majority ofpatients are healthy). Applications are in all fields of medicalimaging, including radiology, ultrasound, PET scans, or microscopyanalysis.

In dataset cleaning for large databases of images, anomaly detection canidentify outliers, which should be carefully checked and potentiallyre-labeled. This is a useful pre-processing step for all methods workingon big data, e.g., large scale machine learning or computer vision, withthe benefit that the elimination of anomalous data prevents learning ofwrong concepts.

In autonomous driving, visual anomaly detection can identify scenes thatare out of scope of the training data on which the autopilot wastrained. In such situations it might be advisable to hand control backto the human driver to avoid safety issues.

The method can also be used for the analysis of image-like data.Although some sensors do not produce images, their recordings can berepresented as images, e.g., spectrograms after Fourier Transform. Thisallows using the presented methods to identify anomalous recordings fromother sensory domains, e.g., anomalous sounds or radar recordings, ifthe Adversarial Autoencoder is applied to the 2-dimensionalspectrograms.

What is claimed is:
 1. A method comprising: in a first training,training the Adversarial Autoencoder using a training dataset of images,thereby optimizing the Adversarial Autoencoder such that: a distributionof latent representations of images of the training dataset of imagesapproaches a predetermined prior distribution; and a reconstructionerror of reconstructed images of the training dataset of images isminimized; after the first training, detecting anomalies in the latentrepresentation; in a second training, training the AdversarialAutoencoder using the training dataset of images and taking into accountthe detected anomalies; and detecting an anomalous image among a firstdataset of images by the trained Adversarial Autoencoder dependent onone or both of the following: a reconstruction error of the anomalousimage and a probability density under the predetermined priordistribution.
 2. The method of claim 1, wherein the detection of theanomalies in the latent representation is done dependent on an expectedanomaly rate.
 3. The method of claim 1, wherein the detection of theanomalies in the latent representation is done dependent on at least oneof the reconstruction error of the reconstructed images and theprobability density under the predetermined prior distribution.
 4. Themethod of claim 1, wherein the detection of the anomalies in the latentrepresentation is done using a one-class support vector machine or alocal outlier factor algorithm.
 5. The method of claim 1, wherein theanomalies detected in the latent representation are taken into accountby excluding detected anomalies from the training set for the secondtraining.
 6. The method of claim 1, wherein the anomalies detected inthe latent representation are taken into account by using a weightedloss function for tuning the Adversarial Autoencoder in at least onesubsequent training, by which weighted loss function anomalies detectedin the latent representation receive a reduced weight in the at leastone subsequent training.
 7. The method of claim 1, wherein the anomaliesdetected in the latent representation are taken into account bymodifying a reconstruction target for each of a set of the anomaliesdetected in the latent representation to a noise-corrupted version ofitself for at least one subsequent training.
 8. The method of claim 1,wherein the anomalies detected in the latent representation are takeninto account by modifying a reconstruction target for each of a set ofthe anomalies detected in the latent representation to an image close orclosest in the latent space that is identified as not being anomalous inat least one subsequent training.
 9. The method of claim 1, wherein thefirst training and the second training are repeatedly conductedconsecutively a predefined number of times or until a training target isreached.
 10. The method of claim 1, wherein the first training includesa predefined number of iterations.
 11. The method of claim 1, whereinthe second training includes a predefined number of iterations.
 12. Themethod of claim 1, wherein the predetermined prior distribution includesat least one dedicated rejection dass.
 13. The method of claim 1,wherein images of the training dataset of images are initiallyunlabeled.
 14. The method of claim 1, wherein the method includes aquery to a user to identify a presented image as normal or anomalous.15. The method of claim 14, wherein the detected anomalies in the latentrepresentation taken into account in the second training includeuser-identified anomalies.
 16. The method of claim 14, wherein thedetection of the anomalies in the latent representation is done using aone-class support vector machine or a local outlier factor algorithmtrained in a training that excludes images of the training dataset ofimages identified by the user as normal or as anomalous.
 17. The methodof claim 14, wherein images presented to the user are selected dependenton respective anomaly scores.
 18. The method of claim 17, wherein theanomaly score is calculated based on at least one of the reconstructionerror and the probability density under the predetermined priordistribution.
 19. The method of claim 1, wherein an anomaly score forimages in the first dataset of images is output.
 20. The method of claim1, wherein an anomaly score for images in the training dataset of imagesis output.
 21. The method of claim 1, further comprising using thedetection of the anomalous image in a visual quality inspection, in amedical image analysis, in a visual surveillance, or in an automateddriving.
 22. A non-transitory computer-readable medium on which arestored instructions that are executable by a processor and that, whenexecuted by the processor, cause the processor to perform a method, themethod comprising: in a first training, training the AdversarialAutoencoder using a training dataset of images, thereby optimizing theAdversarial Autoencoder such that: a distribution of latentrepresentations of images of the training dataset of images approaches apredetermined prior distribution; and a reconstruction error ofreconstructed images of the training dataset of images is minimized;after the first training, detecting anomalies in the latentrepresentation; in a second training, training the AdversarialAutoencoder using the training dataset of images and taking into accountthe detected anomalies; and detecting an anomalous image among a firstdataset of images by the trained Adversarial Autoencoder dependent onone or both of the following: a reconstruction error of the anomalousimage and a probability density under the predetermined priordistribution.
 23. A computer comprising a processor programmed toexecute a method, the method comprising: in a first training, trainingthe Adversarial Autoencoder using a training dataset of images, therebyoptimizing the Adversarial Autoencoder such that: a distribution oflatent representations of images of the training dataset of imagesapproaches a predetermined prior distribution; and a reconstructionerror of reconstructed images of the training dataset of images isminimized; after the first training, detecting anomalies in the latentrepresentation; in a second training, training the AdversarialAutoencoder using the training dataset of images and taking into accountthe detected anomalies; and detecting an anomalous image among a firstdataset of images by the trained Adversarial Autoencoder dependent onone or both of the following: a reconstruction error of the anomalousimage and a probability density under the predetermined priordistribution.